/*
 * Copyright 2012 Alan Burlison, alan@bleaklow.com.  All rights reserved.
 * Use is subject to license terms.  See LICENSE.txt for details.
 */

/*
 * Requires and is based in part on example code from:
 *     LUFA Library Copyright (C) Dean Camera, 2012.
 *     dean [at] fourwalledcubicle [dot] com www.lufa-lib.org
 * See License.txt in the LUFA distribution for LUFA license details.
 */

/*
 * LUFA-based CDC-ACM serial port support.  This extends the LUFA implementation
 * by adding basic line discipline handling - CR/NL handling, echoing, backspace
 * handling etc.
 */

#ifndef USBSerial_h
#define	USBSerial_h

#include <Task.h>
#include <usb_serial.h>

class USBSerial : public Task {
public:
    /*
     * Create a new USB Serial connection, returning two stdio streams.
     * See usb_serial.h for iomode values.
     */
    USBSerial(uint8_t iomode, FILE **in, FILE **out);

    /*
     * Create a new USB Serial connection, setting stdin, stdout and stderr to
     * the opened streams.  See usb_serial.h for iomode values.
     */
    USBSerial(uint8_t iomode);

    /*
     * Run the LUFA USB handling code.  Needs to be called regularly, at least
     * every 25 milliseconds.
     */
    virtual bool run(uint32_t now);

    /*
     * Return the number of input characters available.
     */
    inline int inputChars(void) { return usb_serial_input_chars(); }

    /*
     * Return the number of input lines available.
     */
    inline int inputLines(void) { return usb_serial_input_lines(); }
};

#endif	/* USBSerial_h */

